import { create } from "zustand";
import { persist, devtools } from "zustand/middleware";
import { immer } from "zustand/middleware/immer";


type AppStoreType = typeof initState;


const initState = {
    token: ''
}


const useAppStore = create<AppStoreType>()(

    immer(
        devtools(
            persist(
                () => {
                    return {
                        ...initState
                    }
                },
                { name: "app-chat-store" }//数据持久化配置
            ),
            { name: "app-chat-store" }//调试工具配置
        )
    )

)


export default useAppStore;

//修改store数据函数


//为token赋值的函数
export const setToken = (token: string) => {
    useAppStore.setState((state) => {
        state.token = token
    })
}